package com.app.controller;


import com.app.entity.Banner;
import com.app.service.BannerService;
import com.app.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jt
 * @since 2021-04-07
 */
@RestController
@RequestMapping("/banner")
public class BannerController {
    @Autowired
    private BannerService carmapService;
    /**
     * 上传
     */
    @PostMapping("/upload")
    public Result upload(@RequestParam("file") MultipartFile file, @RequestParam("weight") Integer weight) {
        carmapService.upload(file, weight);
        return Result.success();
    }

    /**
     * 查询轮播图
     */
    @GetMapping("/getCarMap")
    public Result getCarMap() {
        return Result.success(carmapService.getCarMap());
    }

    /**
     * 修改权重
     */
    @PostMapping("/updateCarMapWeight")
    public Result updateCarMapWeight(@RequestBody Banner banner) {
        carmapService.updateCarMapWeight(banner);
        return Result.success();
    }

    /**
     * 删除轮播图
     */
    @GetMapping("/deleteCarMap/{id}")
    public Result deleteCarMap(@PathVariable Integer id) {
        carmapService.deleteCarMap(id);
        return Result.success();
    }

}

